home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 1 / CU Amiga Magazine CD-ROM Special Edition (1995)(EMAP Images)(GB)[Issue 1995-11].iso / Aminet / comm / tcp / AmiTCPsdk_40.lha / AmiTCP-4.0 / doc / netlib.doc < prev    next >
Text File  |  1994-10-15  |  61KB  |  1,835 lines

  1. TABLE OF CONTENTS
  2.  
  3. net.lib/autoinit
  4. net.lib/autoinit_timer.device
  5. net.lib/autoinit_usergroup.library
  6. net.lib/charRead
  7. net.lib/chmod
  8. net.lib/chown
  9. net.lib/dup
  10. net.lib/dup2
  11. net.lib/fstat
  12. net.lib/gettimeofday
  13. net.lib/herror
  14. net.lib/init_inet_daemon
  15. net.lib/lineRead
  16. net.lib/lstat
  17. net.lib/perror
  18. net.lib/popen
  19. net.lib/PrintNetFault
  20. net.lib/PrintUserFault
  21. net.lib/rcmd
  22. net.lib/serveraccept
  23. net.lib/set_socket_stdio
  24. net.lib/sleep
  25. net.lib/SPrintf
  26. net.lib/stat
  27. net.lib/strerror
  28. net.lib/syslog
  29. net.lib/usleep
  30. net.lib/utime
  31. netd.lib/dosio_init
  32. net.lib/autoinit                                             net.lib/autoinit
  33.  
  34.    NAME
  35.        autoinit - SAS C Autoinitialization Functions
  36.  
  37.    SYNOPSIS
  38.        LONG _STI_200_openSockets(void)
  39.  
  40.        void _STD_200_closeSockets(void)
  41.  
  42.    FUNCTION
  43.        These functions open and close the bsdsocket.library at the startup
  44.        and exit of the program, respectively.  For a program to use these
  45.        functions, it must be linked with netlib:net.lib (or some variant).
  46.        These functions are linked in only if the program references the
  47.        global symbol "SocketBase".
  48.  
  49.        If the library can be opened, the _STI_200_openSockets() calls
  50.        bsdsocket.library function SocketBaseTags() to tell the library the
  51.        address and the size of the errno variable of the calling program,
  52.        the program name (to be used in syslog() messages) and the address
  53.        of the h_error variable (in which the name resolver errors are
  54.        returned).
  55.  
  56.    NOTES
  57.        _STI_200_openSockets() also checks that the system version is at
  58.        least 37. It also puts up a requester if the bsdsocket.library is
  59.        not found or is of wrong version.
  60.  
  61.        The autoinitialization and autotermination functions are features
  62.        specific to the SAS C6.  However, these functions can be used with
  63.        other (ANSI) C compilers, too. Example follows:
  64.  
  65.        /* at start of main() */
  66.  
  67.        atexit(_STD_200_closeSockets);
  68.        if (_STI_200_openSockets() != 0)
  69.           exit(20);
  70.  
  71.    BUGS
  72.        The same autoinitialization won't work for both SAS C 6.3 and SAS C
  73.        6.50 or latter.  Only way to terminate an initialization function is
  74.        by exit() call with SAS C 6.3 binary.  If an autoinitialization
  75.        function is terminated by exit() call with SAS C 6.50 binary, the
  76.        autotermination functions won't be called.  Due this braindamage
  77.        these compilers require separate net.lib libraries.
  78.  
  79.    SEE ALSO
  80.        bsdsocket.library/SocketBaseTags(),
  81.        SAS/C 6 User's Guide p. 145 for details of autoinitialization and
  82.        autotermination functions.
  83.  
  84. net.lib/autoinit_timer.device                   net.lib/autoinit_timer.device
  85.  
  86.    NAME
  87.        timerinit - SAS C Autoinitialization Functions for timer.device
  88.  
  89.    SYNOPSIS
  90.        #include <time.h>
  91.    
  92.        int daylight;
  93.        long timezone;
  94.        char *tzname[2];
  95.  
  96.        void tzset(void);
  97.  
  98.        #include <sys/time.h>
  99.  
  100.        struct Device *TimerBase;
  101.  
  102.        LONG _STI_200_openTimer(void);
  103.        void _STD_200_closeTimer(void);
  104.        
  105.    FUNCTION
  106.        These functions open and close the timer.device at the startup and
  107.        exit of the program, respectively. For a program to use these
  108.        functions, it must be linked with netlib:net.lib.
  109.  
  110.        The opened device base is stored in the TimerBase global variable.
  111.  
  112.        If the device can be opened, the _STIopenTimer() sets up the time zone
  113.        information, which is used by the gettimeofday() function and the time
  114.        conversion routines of the C-library.
  115.  
  116.    NOTES
  117.        The time zone information is got from the environment variable named
  118.        TZ. The format for this variable is:
  119.  
  120.            zzznnnddd
  121.  
  122.        where zzz is three letter identifier for the time zone (for example
  123.        GMT), and the nnn is hours west from Greenwich on range [-23,24]
  124.        (negative values are to east).  The last field is the abbreviation for
  125.        the local daylight saving time zone (which is not interpreted by this
  126.        version).
  127.  
  128.        If the TZ environment variable cannot be found, Greenwich Mean Time
  129.        (GMT) is used instead.
  130.  
  131.        The autoinitialization and autotermination functions are features
  132.        specific to the SAS C6.  However, these functions can be used with
  133.        other (ANSI) C compilers, too.  Example follows:
  134.  
  135.        /* at start of main() */
  136.  
  137.        atexit(_STD_200_closeTimer);
  138.        _STI_200_openTimer();
  139.  
  140.        The tzset() does nothing. All the necessary initialization is done at
  141.        the autoinit function.
  142.  
  143.    BUGS
  144.        TZ "hours west from GMT" should be interpreted as float.
  145.  
  146.        The same autoinitialization won't work for both SAS C 6.3 and SAS C
  147.        6.50 or latter.  Only way to terminate an initialization function is
  148.        by exit() call with SAS C 6.3 binary.  If an autoinitialization
  149.        function is terminated by exit() call with SAS C 6.50 binary, the
  150.        autotermination functions won't be called.  Due this braindamage
  151.        these compilers require separate net.lib libraries.
  152.  
  153.    SEE ALSO
  154.        net.lib/gettimeofday(),
  155.        SAS/C 6 User's Guide p. 145 for details of autoinitialization and
  156.        autotermination functions.
  157. net.lib/autoinit_usergroup.library         net.lib/autoinit_usergroup.library
  158.  
  159.    NAME
  160.        autoinit usergroup.library - SAS C Autoinitialization Functions
  161.  
  162.    SYNOPSIS
  163.        error = _STI_200_openUserGroup()
  164.  
  165.        LONG _STI_200_openUserGroup(void)
  166.  
  167.        _STD_200_closeUserGroup()
  168.  
  169.        void _STD_200_closeUserGroup(void)
  170.  
  171.    FUNCTION
  172.        These functions open and close the usergroup.library at the startup
  173.        and exit of the program, respectively.  For a program to use these
  174.        functions, it must be linked with netlib:usr.lib.
  175.  
  176.    NOTES
  177.        _STI_200_openUserGroup() also checks that the system version is at
  178.        least 37.  It puts up a requester if the usergroup.library is not
  179.        found or is too old version.
  180.  
  181.        The autoinitialization and autotermination functions are features
  182.        specific to the SAS C6.  However, these functions can be used with
  183.        other (ANSI) C compilers, too.  Example follows:
  184.  
  185.        /* at start of main() */
  186.  
  187.        atexit(_STD_200_closeUserGroup);
  188.        if (_STI_200_openUserGroup() != 0)
  189.           exit(20);
  190.  
  191.    BUGS 
  192.        The same autoinitialization won't work for both SAS C 6.3 and SAS C
  193.        6.50 or latter.  Only way to terminate an initialization function is
  194.        by exit() call with SAS C 6.3 binary.  If an autoinitialization
  195.        function is terminated by exit() call with SAS C 6.50 binary, the
  196.        autotermination functions won't be called.  Due this braindamage
  197.        these compilers require separate net.lib libraries.
  198.  
  199.    SEE ALSO
  200.        SAS/C 6 User's Guide p. 145 for details of autoinitialization and
  201.        autotermination functions.
  202.  
  203. net.lib/charRead                                             net.lib/charRead
  204.  
  205.    NAME
  206.        charRead -- read characters from socket one by one.
  207.  
  208.    SYNOPSIS
  209.        initCharRead(rc, fd)
  210.  
  211.        void initCharRead(struct CharRead *, int);
  212.  
  213.  
  214.        character = charRead(rc)
  215.  
  216.        int charRead(struct CharRead *);
  217.  
  218.  
  219.    DESCRIPTION
  220.        charRead is a macro package which return characters one by one 
  221.        from given socket input stream. The socket where data is to be read
  222.        is set by calling initCharRead(): rc is the pointer to charread
  223.        structure previously allocated. fd is the (socket) descriptor where
  224.        reading is to be done.
  225.  
  226.        charRead() returns the next character from input stream or one of
  227.        the following:
  228.  
  229.        RC_DO_SELECT    (-3)    - read input buffer is returned. Do select
  230.                                  before next call if you don't want charread
  231.                                  to block.
  232.  
  233.        RC_EOF          (-2)    - end-of-file condition has occurred.
  234.  
  235.        RC_ERROR        (-1)    - there has been an error while filling new
  236.                                  charread buffer. Check the value of Errno()
  237.  
  238.    NOTE
  239.        Always use variable of type int to store return value from charRead()
  240.        since the numeric value of characters returned may vary between
  241.        0 -255 (or even greater). As you may know, -3 equals 253 if of type
  242.        unsigned char.
  243.  
  244.    EXAMPLE
  245.        /*
  246.         * This piece of code shows how to use charread with select()
  247.         */
  248.        #include <sys/types.h>
  249.        #include <sys/socket.h>
  250.        #include <charread.h>
  251.  
  252.        main_loop(int sock)
  253.        {
  254.          struct CharRead rc;
  255.          fd_set readfds;
  256.          int c;
  257.  
  258.          initCharRead(&rc, sock);
  259.  
  260.          FD_ZERO(&readfds);
  261.  
  262.          while(1) {
  263.            FD_SET(sock, &readfds);     
  264.  
  265.            if (select(sock + 1. &readfds, NULL, NULL, NULL)) < 0) {
  266.              perror("select");
  267.              break;
  268.            }
  269.            if (FD_ISSET(sock, &readfds)) {
  270.              while((c = charRead(&rc)) >= 0)
  271.                handle_next_input_character(c);
  272.              if (c == RC_EOF)
  273.                break;
  274.              if (c == RC_ERROR) {
  275.                perror("charRead");
  276.                break;
  277.              }
  278.            }
  279.          }
  280.        }
  281.  
  282.     PORTABILITY
  283.        The source file charread.h should be able to be used in 
  284.        UNIX programs as is.
  285.  
  286.     SEE ALSO
  287.        lineRead(), bsdsocket.library/recv()
  288. net.lib/chmod                                                   net.lib/chmod
  289.  
  290.    NAME
  291.        chmod, fchmod - change mode of file
  292.  
  293.    SYNOPSIS
  294.        #include <sys/stat.h>
  295.  
  296.        int chmod(const char *path, mode_t mode);
  297.  
  298.        int fchmod(int fd, mode_t mode);
  299.  
  300.    DESCRIPTION
  301.        The function chmod() sets the file permission bits of the file
  302.        specified by the pathname path to mode. Fchmod() sets the permission
  303.        bits of the specified file descriptor fd. Chmod() verifies that the
  304.        process owner (user) either owns the file specified by path (or fd),
  305.        or is the super-user.  A mode is created from or'd permission bit
  306.        masks defined in <sys/stat.h>:
  307.  
  308.              #define S_IRWXU 0000700    /* RWX mask for owner */
  309.              #define S_IRUSR 0000400    /* R for owner */
  310.              #define S_IWUSR 0000200    /* W for owner */
  311.              #define S_IXUSR 0000100    /* X for owner */
  312.  
  313.              #define S_IRWXG 0000070    /* RWX mask for group */
  314.              #define S_IRGRP 0000040    /* R for group */
  315.              #define S_IWGRP 0000020    /* W for group */
  316.              #define S_IXGRP 0000010    /* X for group */
  317.  
  318.              #define S_IRWXO 0000007    /* RWX mask for other */
  319.              #define S_IROTH 0000004    /* R for other */
  320.              #define S_IWOTH 0000002    /* W for other */
  321.              #define S_IXOTH 0000001    /* X for other */
  322.  
  323.              #define S_ISUID 0004000    /* set user id on execution */
  324.              #define S_ISGID 0002000    /* set group id on execution */
  325.              #define S_ISVTX 0001000    /* save swapped text even after use *
  326. /
  327.  
  328.        The ISVTX (the sticky bit) indicates to the system which executable
  329.        files are shareable (pure).
  330.  
  331.        Writing or changing the owner of a file turns off the set-user-id
  332.        and set-group-id bits unless the user is the super-user.  This makes
  333.        the system somewhat more secure by protecting set-user-id
  334.        (set-group-id) files from remaining set-user-id (set-group-id) if
  335.        they are modified.
  336.  
  337.    RETURN VALUES
  338.        Upon successful completion, a value of 0 is returned.  Otherwise, a
  339.        value of -1 is returned and errno is set to indicate the error.
  340.  
  341.    ERRORS
  342.        Chmod() will fail and the file mode will be unchanged if:
  343.  
  344.        [ENOTDIR]     A component of the path prefix is not a directory.
  345.  
  346.        [ENAMETOOLONG]
  347.                      A component of a pathname exceeded 255 characters, or
  348.                      an entire path name exceeded 1023 characters.
  349.  
  350.        [ENOENT]      The named file does not exist.
  351.  
  352.        [EACCES]      Search permission is denied for a component of the
  353.                      path prefix.
  354.  
  355.        [EPERM]       The effective user ID does not match the owner of the
  356.                      file and the effective user ID is not the super-user.
  357.  
  358.        [EROFS]       The named file resides on a read-only file system.
  359.  
  360.        [EFAULT]      Path points outside the process's allocated address
  361.                      space.
  362.  
  363.        [EIO]         An I/O error occurred while reading from or writing to
  364.                      the file system.
  365.  
  366.        Fchmod() will fail if:
  367.  
  368.        [EBADF]       The descriptor is not valid.
  369.  
  370.        [EINVAL]      Fd refers to a socket, not to a file.
  371.  
  372.        [EROFS]       The file resides on a read-only file system.
  373.  
  374.        [EIO]         An I/O error occurred while reading from or writing to
  375.                      the file system.
  376.  
  377.    NOTES
  378.        This call is provided for Unix compatibility.  It does not know all
  379.        Amiga protection bits (Delete, Archive, Script).  The archive and
  380.        script bits are cleared, Delete set according the Write bit.
  381.  
  382.    SEE ALSO
  383.        open(),  chown(),  stat()
  384.  
  385. net.lib/chown                                                   net.lib/chown
  386.  
  387.    NAME
  388.        chown - change owner and group of a file
  389.  
  390.    SYNOPSIS
  391.        #include <unistd.h>
  392.  
  393.        success = chown(path, owner, group)
  394.  
  395.        int chown(const char *, uid_t, gid_t);
  396.  
  397.    DESCRIPTION
  398.        The owner ID and group ID of the file named by path or referenced by
  399.        fd is changed as specified by the arguments owner and group.  The
  400.        owner of a file may change the group to a group of which he or she is
  401.        a member, but the change owner capability is restricted to the
  402.        super-user.
  403.  
  404.        Chown() clears the set-user-id and set-group-id bits on the file to
  405.        prevent accidental or mischievious creation of set-user-id and
  406.        set-group-id programs.
  407.  
  408.        One of the owner or group id's may be left unchanged by specifying it
  409.        as -1.
  410.  
  411.        If the final component of path is a symbolic link, the ownership and
  412.        group of the symbolic link is changed, not the ownership and group of
  413.        the file or directory to which it points.
  414.  
  415.    RETURN VALUES
  416.        Zero is returned if the operation was successful; -1 is returned if an
  417.        error occurs, with a more specific error code being placed in the
  418.        global variable errno.
  419.  
  420.    ERRORS
  421.        Chown() will fail and the file will be unchanged if:
  422.  
  423.        [ENOTDIR]     A component of the path prefix is not a directory.
  424.  
  425.        [EINVAL]      The pathname contains a character with the high-order
  426.                      bit set.
  427.  
  428.        [ENAMETOOLONG]
  429.                      A component of a pathname exceeded 80 characters, or an
  430.                      entire path name exceeded 1023 characters.
  431.  
  432.        [ENOENT]      The named file does not exist.
  433.  
  434.        [EACCES]      Search permission is denied for a component of the path
  435.                      prefix.
  436.  
  437.        [ELOOP]       Too many symbolic links were encountered in translating
  438.                      the pathname.
  439.  
  440.        [EPERM]       The effective user ID is not the super-user.
  441.  
  442.        [EROFS]       The named file resides on a read-only file system.
  443.  
  444.        [EFAULT]      Path points outside the process's allocated address
  445.                      space.
  446.  
  447.        [EIO]         An I/O error occurred while reading from or writing to
  448.                      the file system.
  449.  
  450.    SEE ALSO
  451.        chmod(2)
  452.  
  453. net.lib/dup                                                       net.lib/dup
  454.  
  455.    NAME
  456.        dup, dup2 - duplicate an existing file descriptor
  457.  
  458.    SYNOPSIS
  459.        #include <unistd.h>
  460.  
  461.        int dup(int oldd)
  462.  
  463.        int dup2(int oldd, int newd)
  464.  
  465.    FUNCTION
  466.        Dup() duplicates an existing object descriptor and returns its value
  467.        to the calling program (newd = dup(oldd)). The argument oldd is a
  468.        small nonnegative integer index in the program's descriptor table.
  469.        The value must be less than the size of the table, which is returned
  470.        by getdtablesize().  The new descriptor returned by the call is the
  471.        lowest numbered descriptor currently not in use by the program.
  472.  
  473.        The object referenced by the descriptor does not distinguish between
  474.        oldd and newd in any way.  Thus if newd and oldd are duplicate
  475.        references to an open file, read() and write() calls all move a single
  476.        pointer into the file, and append mode, non-blocking I/O and
  477.        asynchronous I/O options are shared between the references.  If a
  478.        separate pointer into the file is desired, a different object
  479.        reference to the file must be obtained by issuing an additional open()
  480.        call.  The close-on-exec flag on the new file descriptor is unset.
  481.  
  482.        In dup2(), the value of the new descriptor newd is specified.  If this
  483.        descriptor is already in use, the descriptor is first deallocated as
  484.        if a close() call had been done first.
  485.  
  486.    RETURN VALUES
  487.        The value -1 is returned if an error occurs in either call.  The
  488.        external variable errno indicates the cause of the error.
  489.  
  490.    BUGS
  491.        The current UFB implementation for SAS C allows only sockets to be
  492.        duplicated.
  493.  
  494.    ERRORS
  495.        Dup() and dup2() fail if:
  496.  
  497.        [EBADF]       Oldd or newd is not a valid active descriptor
  498.  
  499.        [EMFILE]      Too many descriptors are active.
  500.  
  501.    SEE ALSO
  502.        accept(),  open(),  close(),  socket(),  getdtablesize()
  503.  
  504.    STANDARDS
  505.        Dup() and dup2() are expected to conform to IEEE Std 1003.1-1988
  506.        (``POSIX'').
  507.  
  508.    COPYRIGHT
  509.        This manual page is copyright © 1980, 1991 Regents of the
  510.        University of California.  All rights reserved.
  511.  
  512. net.lib/dup2                                                     net.lib/dup2
  513.    SEE ALSO
  514.        dup()
  515. net.lib/fstat                                                   net.lib/fstat
  516.  
  517.    SEE ALSO
  518.        stat()
  519.  
  520. net.lib/gettimeofday                                     net.lib/gettimeofday
  521.  
  522.    NAME   
  523.        gettimeofday - get date and time 
  524.  
  525.    SYNOPSIS
  526.        #include <sys/time.h>
  527.  
  528.        error = gettimeofday(tp, tzp)
  529.  
  530.        int gettimeofday(struct timeval *, struct timezone *)
  531.  
  532.    FUNCTION
  533.        The system's notion of the current Greenwich time and the
  534.        current time zone is obtained with the gettimeofday() call.
  535.        The time is expressed in seconds and microseconds since
  536.        midnight (0 hour), January 1, 1970.  The resolution of the
  537.        system clock is hardware dependent. If tzp is zero, the time
  538.        zone information will not be returned. Also, if your system
  539.        software is unable to provide time zone information, the
  540.        structure pointed by tzp will be filled with zeroes.
  541.   
  542.    PORTABILITY
  543.        UNIX
  544.  
  545.    INPUTS
  546.        The structures pointed to by tp and tzp are defined in
  547.        <sys/time.h> as:
  548.   
  549.             struct timeval {
  550.                  long tv_sec;      /* seconds since Jan. 1, 1970 */
  551.                  long tv_usec;     /* and microseconds */
  552.             };
  553.   
  554.             struct timezone {
  555.                  int  tz_minuteswest;   /* of Greenwich */
  556.                  int  tz_dsttime;  /* type of dst correction to apply */
  557.             };
  558.   
  559.        The timezone structure indicates the local time zone (meas-
  560.        ured in minutes of time westward from Greenwich), and a flag
  561.        that, if nonzero, indicates that Daylight Saving time
  562.        applies locally during the appropriate part of the year.
  563.  
  564.    RESULT
  565.        Returns 0 when successful and -1 with specific error code in 
  566.        errno in case of an error. No error codes are specified,
  567.        however.
  568.        
  569.    NOTES
  570.        gettimeofday() uses GetSysTime() function of the timer.device,
  571.        which is new to V36 of the device.
  572.  
  573.        Time zone information is taken from the locale.library, if it
  574.        is available (it is included in all Amiga systems from 2.1 and
  575.        up). Otherwise the environment variable "TZ" is consulted. If
  576.        it fails, the time zone is initialized to the GMT.
  577.  
  578.        Global variable TimerBase _must_ be initialized before
  579.        gettimeofday() is called. This is normally done automatically
  580.        by the autoinit module (timerinit.c) included in the net.lib.
  581.  
  582.    SEE ALSO
  583.        timer.device/GetSysTime()
  584. net.lib/herror                                                 net.lib/herror
  585.  
  586.    NAME
  587.        herror - print name resolver error message to stderr.
  588.  
  589.    SYNOPSIS
  590.        #include <clib/netlib_protos.h>
  591.  
  592.        herror(banner)
  593.        void herror(const char *)
  594.  
  595.    FUNCTION
  596.        The herror() function finds the error message corresponding to the
  597.        current value of host error using the SocketBaseTags() and writes
  598.        it, followed by a newline, to the stderr. If the argument string
  599.        is non-NULL it is used as a prefix to the message string and
  600.        separated from it by a colon and space (`: '). If the argument is
  601.        NULL only the error message string is printed.
  602.  
  603.    NOTES
  604.        The herror() function requires the stdio functions to be linked.
  605.  
  606.    SEE ALSO
  607.        <netinclude:netdb.h>, SocketBaseTagList(), perror()
  608.  
  609. net.lib/init_inet_daemon                             net.lib/init_inet_daemon
  610.  
  611.    NAME
  612.        init_inet_daemon - obtain socket accepted by the inetd
  613.  
  614.    SYNOPSIS
  615.        int init_inet_daemon(void);
  616.  
  617.    FUNCTION
  618.        Obtain the server socket accepted by the inetd, the Internet
  619.        super-server.
  620.  
  621.    RETURN VALUES
  622.        socket descriptor if successful, -1 with specific error code
  623.        on errno otherwise.
  624.  
  625.    ERRORS
  626.        ENXIO     - The process was not started by the inetd.
  627.  
  628.    NOTES
  629.        If the process was started by the inetd, but the ObtainSocket()
  630.        call fails, then this function exit()s with some specific exit
  631.        code, so that inetd can clean up the unobtained socket.
  632.  
  633.        Use the net.lib function set_socket_stdio() to redirect stdio,
  634.        stdout and stderr to the returned socket, if necessary.
  635.  
  636.    SEE ALSO
  637.        serveraccept(), set_socket_stdio(), bsdsocket/ObtainSocket(),
  638.        netutil/inetd
  639. net.lib/lineRead                                             net.lib/lineRead
  640.  
  641.    NAME
  642.        lineRead -- read newline terminated strings from socket
  643.  
  644.    SYNOPSIS
  645.        initLineRead(rl, fd, lftype, bufsize)
  646.  
  647.        void initLineRead(struct LineRead *, int, int, int);
  648.  
  649.  
  650.        length = lineRead(rl)
  651.  
  652.        int lineread(struct LineRead *);
  653.  
  654.  
  655.    FUNCTION
  656.        lineRead() reads newline terminated strings from given descriptor
  657.        very efficiently. All the options needed are set by calling
  658.        initLineRead(): rl is the pointer to lineread structure previously
  659.        allocated. fd is the (socket) descriptor where reading is to be
  660.        done. lftype can have following 3 values:
  661.  
  662.            RL_LFNOTREQ - Newline terminated strings are returned unless
  663.                          there is no newlines left in currently buffered
  664.                          input. In this case remaining buffer is returned.
  665.  
  666.            RL_LFREQLF  - If there is no newlines left in currently buffered
  667.                          input the remaining input data is copied at the
  668.                          start of buffer. Caller is informed that next
  669.                          call will fill the buffer (and it may block).
  670.                          Lines are always returned with newline at the end
  671.                          unless the string is longer than whole buffer.
  672.  
  673.            RL_LFREQNUL  - Like LF_REQLF, but remaining newline is removed.
  674.                          Note here that lenght is one longer that actual
  675.                          string length since line that has only one
  676.                          newline at the end would return length as 0
  677.                          which indigate string incomplete condition.
  678.  
  679.        bufsize is used to tell lineread how big the receive buffer is.
  680.        always put RL_BUFSIZE here since that value is used to determine
  681.        the memory allocated for the buffer. This option is given to you
  682.        so you may decide to use different buffer size than the default
  683.        1024.
  684.  
  685.        lineRead() returns the newline terminated string in rl_line field
  686.        of lineread structure. Return values of lineRead() are:
  687.  
  688.             1 - RL_BUFSIZE     - normal length of returned string.
  689.  
  690.             0                  - If zero is returned just after select(),
  691.                                  end-of-file condition has occurred.
  692.                                  Otherwise string is not completed yet.
  693.                                  Make sure you call select() (or use non-
  694.                                  blocking IO) if you don't want next call
  695.                                  to block.
  696.  
  697.            -1                  - if rl_Line field of lineread structure
  698.                                  is NULL, it indicates error condition.
  699.                                  If rl_Line points to start of string
  700.                                  buffer, input string has been longer
  701.                                  than buffer. In this case rl_Line points
  702.                                  to zero terminated string of length
  703.                                  RL_BUFSIZE.
  704.  
  705.        You may modify the zero terminated string returned by lineRead() in
  706.        any way, but memory around the string is private lineread memory.
  707.  
  708.    EXAMPLE
  709.        /*
  710.         * The following code shows how to use lineread with select()
  711.         */
  712.        #ifdef USE_LOW_MEMORY_BUFFER
  713.        #define RL_BUFSIZE 256
  714.        #endif
  715.  
  716.        #include <sys/types.h>
  717.        #ifdef AMIGA
  718.        #include <bsdsocket.h>
  719.        #endif
  720.        #include <lineread.h>
  721.  
  722.        #define NULL 0
  723.  
  724.        ...
  725.  
  726.        main_loop(int sock)
  727.        {
  728.          struct LineRead * rl;
  729.          int length;
  730.          fd_set reafdfs;
  731.  
  732.          if (rl = (struct LineRead *)AllocMem(sizeof (*rl), 0)) {
  733.  
  734.            initLineRead(rl, sock, LF_REQLF, RL_BUFSIZE);
  735.  
  736.            FD_ZERO(&readfds);
  737.  
  738.            while(1) {
  739.              FD_SET(sock, &readfds);
  740.  
  741.              if (select(sock + 1, &readfds, NULL, NULL, NULL)) < 0) {
  742.                perror("select");
  743.                break;
  744.              }
  745.              if (FD_ISSET(sock, &readfds))
  746.                if ((length = lineRead(rl)) == 0) /* EOF */
  747.                  break;
  748.                do {
  749.                  if (length > 0)
  750.                    write(1, rl->rl_Line, length); /* stdout. write() for */
  751.                                                   /* speed demonstration */
  752.                  else { /* length == -1 */
  753.                    if (rl->rl_Line == NULL); {
  754.                      perror("lineRead");
  755.                      break;
  756.                    }
  757.                    else {
  758.                      fprintf(stderr, "lineread input buffer overflow!\n");
  759.                      write(1, rl->rl_Line, RL_BUFSIZE);
  760.                      write(1, "\n", 1);
  761.                    }
  762.                  }
  763.                } while ((length = lineRead(rl)) != 0); /* 0 -> do select() */
  764.            }
  765.          FreeMem(rl, sizeof (*rl);
  766.          }
  767.          else
  768.            fprintf("AllocMem: Out Of memory\n");
  769.        }
  770.  
  771.     PORTABILITY
  772.        The source modules lineread.c and lineread.h should compile
  773.        in UNIX machines as is.
  774.  
  775.     SEE ALSO
  776.        charRead(), bsdsocket.library/recv()
  777.  
  778. net.lib/lstat                                                   net.lib/lstat
  779.  
  780.    SEE ALSO
  781.        stat()
  782.  
  783. net.lib/perror                                                 net.lib/perror
  784.  
  785.    NAME
  786.        perror - socket error messages
  787.  
  788.    SYNOPSIS
  789.        extern int errno;
  790.  
  791.        #include <stdio.h>
  792.  
  793.        perror(banner)
  794.        void perror(const char *)
  795.  
  796.    FUNCTION
  797.        The perror() function finds the error message corresponding to the
  798.        current value of the global variable errno and writes it, followed
  799.        by a newline, to the stderr. If the argument string is non-NULL it
  800.        is preappended to the message string and separated from it by a
  801.        colon and space (`: '). If string is NULL only the error message
  802.        string is printed.
  803.  
  804.    NOTES
  805.        The perror() function requires the stdio functions to be linked.
  806.  
  807.    SEE ALSO
  808.        strerror(), PrintNetFault(), <netinclude:sys/errno.h>
  809.  
  810. net.lib/popen                                                   net.lib/popen
  811.    NAME
  812.        popen, pclose - initiate I/O to/from a process
  813.  
  814.    SYNOPSIS
  815.        #include <stdio.h>
  816.  
  817.        FILE *popen(command, type)
  818.        char *command, *type;
  819.  
  820.        pclose(stream)
  821.        FILE *stream;
  822.  
  823.    DESCRIPTION
  824.        The arguments to popen are pointers to null-terminated
  825.        strings containing respectively a command line and an
  826.        I/O mode, either "r" for reading or "w" for writing.  It
  827.        creates a pipe between the calling process and the command
  828.        to be executed.  The value returned is a stream pointer that
  829.        can be used (as appropriate) to write to the standard input
  830.        of the command or read from its standard output.
  831.  
  832.        A stream opened by popen **MUST** be closed by pclose, which
  833.        waits for the associated process to terminate and returns
  834.        the exit status of the command.
  835.  
  836.        Because stdio files are shared, a type "r" command may be
  837.        used as an input filter, and a type "w" as an output filter.
  838.  
  839.    DIAGNOSTICS
  840.        Popen returns a null pointer if files or processes cannot be
  841.        created.
  842.  
  843.        Pclose returns -1 if stream is not associated with a
  844.        `popened' command.
  845.  
  846.    AUTHOR
  847.        Original version by Rick Schaeffer <ricks@isc-br.isc-br.com>
  848. /
  849.  
  850. include <stdio.h>
  851. include <stdlib.h>
  852. include <string.h>
  853. include <stdarg.h>
  854.  
  855. include <exec/types.h>
  856. include <exec/memory.h>
  857. include <dos/dos.h>
  858. include <dos/dosextens.h>
  859. include <dos/record.h>
  860. include <dos/dostags.h>
  861.  
  862. include <proto/exec.h>
  863. include <proto/dos.h>
  864. include <clib/alib_protos.h>
  865.  
  866. include <errno.h>
  867.  
  868. define NOTDEF
  869.  
  870. xtern char *mktemp(char *);
  871.  
  872. truct POmsg {
  873.    struct Message  POm;
  874.    int     rc;
  875.    char        *cmd;
  876.    struct Library  *DOSBase;
  877.    };
  878.  
  879.  
  880. truct pstruct {
  881.    FILE    *fptr;
  882.    struct POmsg    childmsg;
  883.    };
  884.  
  885. define MAXPIPES    6
  886. tatic struct pstruct poarray[MAXPIPES];
  887.  
  888. tatic int childprocess(void);
  889.  
  890. ILE *popen(const char *cmd, const char *mode)
  891.  
  892.    static char tempname[] = "pipe:pXXX.XXX";
  893.    char        *pname,redir[20];
  894.    short       i;
  895.    int         pmode;
  896.    struct pstruct  *poptr;
  897.    BPTR            pfd;
  898.    struct Process  *child;
  899.    struct CommandLineInterface *cli;
  900.    BPTR Binfh, Boutfh;
  901.    ULONG closeinp, closeoutp;
  902.    ULONG stacksize;
  903.    struct Process *thistask;
  904.  
  905.    /* First, get pointers to our process and cli structs */
  906.    thistask = (struct Process *) FindTask(NULL);
  907.    cli = Cli();
  908.    poptr = NULL;
  909.  
  910.    /* now find an open pipe (we currently only allow 6 simultaneously
  911.       open pipes) */
  912.    for (i=0; i<MAXPIPES; i++) {
  913.        if (poarray[i].fptr == NULL) {
  914.            poptr = &poarray[i];
  915.            break;
  916.            }
  917.        }
  918.    if (poptr == NULL) {
  919.        fprintf(stderr,"popen: Unable to find an open pipe\n");
  920.        errno = EMFILE;
  921.        return(NULL);
  922.        }
  923.    if (strcmp(mode,"r") == 0)
  924.        pmode = MODE_NEWFILE;
  925.    else if (strcmp(mode,"w") == 0)
  926.        pmode = MODE_OLDFILE;
  927.    else {
  928.        fprintf(stderr,"popen: Mode must be 'r' or 'w'\n");
  929.        errno = EINVAL;
  930.        return(NULL);
  931.        }
  932.  
  933.    /* Try to make a guaranteed unique file name for the pipe */
  934.    strcpy(redir,tempname);
  935.    redir[5] = 'a' + i;
  936.  
  937.    pname = mktemp(redir);            /* set up a pipe: file name */
  938.  
  939.    /* Now get the child's stack and priority set up */
  940.    if (cli)
  941.        stacksize = cli->cli_DefaultStack << 2;
  942.    else
  943.        stacksize = thistask->pr_StackSize;
  944.  
  945.    /* Open the side of the pipe for the child */
  946.    pfd = Open(pname,pmode);
  947.    if (pfd == 0) {
  948.        errno = __io2errno(_OSERR = IoErr());
  949.        fprintf(stderr,"popen: Unable to open pipe file\n");
  950.        return(NULL);
  951.        }
  952.  
  953.    /* set up the tags for the new process */
  954.    if (pmode == MODE_NEWFILE) {
  955.        Binfh     = (Tag) Input();
  956.        Boutfh    = (Tag) pfd;
  957.        closeinp  = FALSE;
  958.        closeoutp = TRUE;
  959.        }
  960.    else {
  961.        Binfh     = (Tag) pfd;
  962.        Boutfh    = (Tag) Output();
  963.        closeinp  = TRUE;
  964.        closeoutp = FALSE;
  965.        }
  966.  
  967.    /* create the command.  since the "System" function runs through
  968.       the default shell, we need to tell it not to fail so that we
  969.       ALWAYS get back the exit status.  This wouldn't be necessary
  970.       if the CLI created by the System function inherited the parent's
  971.       FAILAT level
  972.    */
  973.    poptr->childmsg.cmd = malloc(strlen(cmd) + 15);
  974.    strcpy(poptr->childmsg.cmd,"failat 9999\n");
  975.    strcat(poptr->childmsg.cmd,cmd);
  976.  
  977.    /* Create a port that we can get the child's exit status through */
  978.    poptr->childmsg.POm.mn_ReplyPort = CreateMsgPort();
  979.    poptr->childmsg.POm.mn_Node.ln_Type = NT_MESSAGE;
  980.    poptr->childmsg.POm.mn_Node.ln_Pri = 0;
  981.    if (poptr->childmsg.POm.mn_ReplyPort == 0) {
  982.        fprintf(stderr,"popen: Couldn't create message port\n");
  983.        errno = ENOMEM;
  984.        return(NULL);
  985.        }
  986.  
  987.    /* Now we can start the new process.  NOTE: this is actually going
  988.       to create a process consisting ONLY of the function "childprocess"
  989.       which can be seen below.  childprocess() then runs the command
  990.       passed in the startup message.
  991.    */
  992.    child = CreateNewProcTags(
  993.        NP_Entry,   (Tag) childprocess,
  994.        NP_Input,   Binfh,
  995.        NP_Output,  Boutfh,
  996.        NP_CloseInput,  closeinp,
  997.        NP_CloseOutput, closeoutp,
  998.        NP_StackSize,   stacksize,
  999.        NP_Cli,     TRUE,
  1000.        TAG_DONE
  1001.        );
  1002.  
  1003.    poptr->childmsg.DOSBase = (struct Library *)DOSBase;
  1004.  
  1005.    /* now pass the child the startup message */
  1006.    PutMsg(&child->pr_MsgPort,(struct Message *) &poptr->childmsg);
  1007.  
  1008.    /* Now open our side of the pipe */
  1009.    poptr->fptr = fopen(pname,mode);
  1010.    if (poptr->fptr == NULL) {
  1011.        fprintf(stderr,"popen: Unable to open pipe file %s\n",pname);
  1012.        DeleteMsgPort(poptr->childmsg.POm.mn_ReplyPort);
  1013.        return(NULL);
  1014.        }
  1015.    return(poptr->fptr);
  1016.  
  1017.  
  1018. ILE *popenl(const char *arg0, ...)
  1019.  
  1020.    va_list ap;
  1021.    char argbuf[512], *mode;
  1022.  
  1023.    strcpy(argbuf, arg0);
  1024.    va_start(ap, arg0);
  1025.    while(1)
  1026.    {
  1027.        char *s = va_arg(ap, char *);
  1028.  
  1029.        if(s == NULL)
  1030.        {
  1031.        strcat(argbuf, "\n");
  1032.        break;
  1033.        } /* if */
  1034.  
  1035.        strcat(argbuf, " ");
  1036.  
  1037.        if(strchr(s, ' '))
  1038.        {
  1039.        strcat(argbuf, "\"");
  1040.        strcat(argbuf, s);
  1041.        strcat(argbuf, "\"");
  1042.        }
  1043.        else
  1044.        {
  1045.        strcat(argbuf, s);
  1046.        } /* if */
  1047.    }
  1048.    mode = va_arg(ap, char *);
  1049.    va_end(ap);
  1050.  
  1051.    return(popen(argbuf, mode));
  1052.  
  1053.  /* popenl */
  1054.  
  1055. nt pclose(FILE *fptr)
  1056.  
  1057.    short       i;
  1058.  
  1059.    /* Figure out which pipe we used for this file */
  1060.    for (i=0; i<MAXPIPES; i++)
  1061.        if (poarray[i].fptr == fptr)
  1062.            break;
  1063.    if (i >= MAXPIPES) {
  1064.        fprintf(stderr,"popen: DISASTER...couldn't find file pointer in pclose
  1065. \n");
  1066.        exit(1);
  1067.        }
  1068.  
  1069.    /* close the file */
  1070.    fclose(fptr);
  1071.  
  1072.    /* now wait for the exit status */
  1073.    WaitPort(poarray[i].childmsg.POm.mn_ReplyPort);
  1074.    poarray[i].fptr = NULL;
  1075.  
  1076.    /* clean things up */
  1077.    DeletePort(poarray[i].childmsg.POm.mn_ReplyPort);
  1078.    free(poarray[i].childmsg.cmd);
  1079.    return(poarray[i].childmsg.rc);
  1080.  
  1081.  
  1082. * SAS/C autoinitialization for cleanup! */
  1083. oid __stdargs _STD_4000_popen(void)
  1084.  
  1085.    short i;
  1086.  
  1087.    /* Close all the open pipes! */
  1088.    for(i=0; i<MAXPIPES; i++)
  1089.    {
  1090.        if(poarray[i].fptr)
  1091.        {
  1092.            pclose(poarray[i].fptr);
  1093.        } /* if */
  1094.    } /* for */
  1095.  
  1096.  /* _STD_4000_popen */
  1097.  
  1098. ifdef NOTDEF
  1099.  
  1100. har *mktemp(char * template)
  1101.  
  1102.    register char *cp;
  1103.    register unsigned long val;
  1104.  
  1105.    cp = template;
  1106.    cp += strlen(cp);
  1107.    for (val = (unsigned long) FindTask(0L) ; ; )
  1108.        if (*--cp == 'X') {
  1109.            *cp = val%10 + '0';
  1110.            val /= 10;
  1111.        } else if (*cp != '.')
  1112.            break;
  1113.  
  1114.    if (*++cp != 0) {
  1115.        *cp = 'A';
  1116.        while (access(template, 0) == 0) {
  1117.            if (*cp == 'Z') {
  1118.                *template = 0;
  1119.                break;
  1120.            }
  1121.            ++*cp;
  1122.        }
  1123.    } else {
  1124.        if (access(template, 0) == 0)
  1125.            *template = 0;
  1126.    }
  1127.    return template;
  1128.  
  1129.  
  1130. endif
  1131.  
  1132. * WATCH OUT! This only works without __saveds because of the special
  1133.   SAS/C 6.1 tricks I use! Check the output with omd! */
  1134. tatic int __interrupt childprocess(void)
  1135.  
  1136.    struct ExecBase *SysBase = *((struct ExecBase **)4);
  1137.    struct Library *DOSBase;
  1138.    struct Process  *me;
  1139.    struct POmsg    *startupmsg;
  1140.    int             i = RETURN_FAIL;
  1141.  
  1142.    /* find our process structure */
  1143.    me = (struct Process *) FindTask(NULL);
  1144.  
  1145.    /* Wait for the parent to kick us off */
  1146.    WaitPort(&me->pr_MsgPort);
  1147.  
  1148.    /* Get the command to execute */
  1149.    startupmsg = (struct POmsg *) GetMsg(&me->pr_MsgPort);
  1150.  
  1151.    DOSBase = startupmsg->DOSBase;
  1152.  
  1153.    if(DOSBase)
  1154.    {
  1155.        /* Now run the command.  stdin and stdout are already set up */
  1156.        i = SystemTags(startupmsg->cmd,
  1157.               SYS_UserShell, 1,
  1158.               TAG_DONE);
  1159.    } /* if */
  1160.  
  1161.    if(i > 0)
  1162.    {
  1163.        /* UNIX compatibility ... */
  1164.        i <<= 8;
  1165.    } /* if */
  1166.  
  1167.    startupmsg->rc = i;
  1168.    /* pass the exit code back to the parent */
  1169.    ReplyMsg((struct Message *) startupmsg);
  1170.    return(0);
  1171.  
  1172. net.lib/PrintNetFault                                   net.lib/PrintNetFault
  1173.  
  1174.    NAME
  1175.        PrintNetFault - socket error messages
  1176.  
  1177.    SYNOPSIS
  1178.        PrintNetFault(code, banner)
  1179.        void PrintNetFault(LONG, const UBYTE *)
  1180.  
  1181.    FUNCTION
  1182.        The PrintNetFault() function finds the error message corresponding
  1183.        to the code and writes it, followed by a newline, to the standard
  1184.        error or Output() filehandle. If the argument string is non-NULL it
  1185.        is preappended to the message string and separated from it by a
  1186.        colon and space (`: '). If string is NULL only the error message
  1187.        string is printed.
  1188.  
  1189.    NOTES
  1190.        The PrintNetFault() function uses the DOS IO functions.
  1191.  
  1192.    SEE ALSO
  1193.        strerror(), perror(), <netinclude:sys/errno.h>
  1194.  
  1195. net.lib/PrintUserFault                                 net.lib/PrintUserFault
  1196.  
  1197.    NAME
  1198.        PrintUserFault - socket error messages
  1199.  
  1200.    SYNOPSIS
  1201.        PrintUserFault(code, banner)
  1202.        void PrintUserFault(LONG, const UBYTE *)
  1203.  
  1204.    FUNCTION
  1205.        The PrintUserFault() function finds the error message corresponding to
  1206.        the code and writes it, followed by a newline, to the standard error
  1207.        or Output() filehandle. If the argument string is non-NULL it is
  1208.        preappended to the message string and separated from it by a colon and
  1209.        space (`: '). If string is NULL only the error message string is
  1210.        printed.
  1211.  
  1212.    NOTES
  1213.        The PrintUserFault() function used the DOS io functions.  It is
  1214.        recommended to use PrintUserFault() when the standard C IO functions
  1215.        are not otherwise in use.
  1216.  
  1217.    SEE ALSO
  1218.        strerror(), perror(), <netinclude:sys/errno.h>
  1219.  
  1220. net.lib/rcmd                                                     net.lib/rcmd
  1221.  
  1222.    NAME
  1223.        rcmd, rresvport - routines for returning a stream to a remote command
  1224.  
  1225.    SYNOPSIS
  1226.        #include <clib/socket_protos.h>
  1227.  
  1228.        int rcmd(char **ahost, int inport, const char *locuser, 
  1229.                 const char *remuser, const char *cmd, int *fd2p);
  1230.  
  1231.        int rresvport(int *port);
  1232.  
  1233.    FUNCTION
  1234.        The rcmd() function is used by the super-user to execute a command on
  1235.        a remote machine using an authentication scheme based on reserved port
  1236.        numbers.  The rresvport() function returns a descriptor to a socket
  1237.        with an address in the privileged port space.  Both functions are
  1238.        present in the same file and are used by the rsh command (among
  1239.        others).
  1240.  
  1241.        The rcmd() function looks up the host *ahost using gethostbyname(),
  1242.        returning -1 if the host does not exist.  Otherwise *ahost is set to
  1243.        the standard name of the host and a connection is established to a
  1244.        server residing at the well-known Internet port inport.
  1245.  
  1246.        If the connection succeeds, a socket in the Internet domain of type
  1247.        SOCK_STREAM is returned to the caller, and given to the remote command
  1248.        as stdin and stdout. If fd2p is non-zero, then an auxiliary channel to
  1249.        a control process will be set up, and a descriptor for it will be
  1250.        placed in *fd2p. The control process will return diagnostic output
  1251.        from the command (unit 2) on this channel, and will also accept bytes
  1252.        on this channel as being UNIX signal numbers, to be forwarded to the
  1253.        process group of the command.  If fd2p is 0, then the stderr (unit 2
  1254.        of the remote command) will be made the same as the stdout and no
  1255.        provision is made for sending arbitrary signals to the remote process,
  1256.        although you may be able to get its attention by using out-of-band
  1257.        data.
  1258.  
  1259.        The protocol is described in detail in netutil/rshd.
  1260.  
  1261.        The rresvport() function is used to obtain a socket with a privileged
  1262.        address bound to it.  This socket is suitable for use by rcmd() and
  1263.        several other functions.  Privileged Internet ports are those in the
  1264.        range 0 to 1023.  Only the super-user is allowed to bind an address of
  1265.        this sort to a socket.
  1266.  
  1267.    DIAGNOSTICS
  1268.        The rcmd() function returns a valid socket descriptor on success.  It
  1269.        returns -1 on error and prints a diagnostic message on the standard
  1270.        error.
  1271.  
  1272.        The rresvport() function returns a valid, bound socket descriptor on
  1273.        success.  It returns -1 on error with the global value errno set
  1274.        according to the reason for failure.  The error code EAGAIN is
  1275.        overloaded to mean `All network ports in use.'
  1276.  
  1277.    SEE ALSO
  1278.        netutil/rlogin,  netutil/rsh,  rexec(),  netutil/rexecd,
  1279.        netutil/rlogind, netutil/rshd
  1280.  
  1281. net.lib/serveraccept                                     net.lib/serveraccept
  1282.  
  1283.    NAME
  1284.        serveraccept - Accept a server connection on named port
  1285.  
  1286.    SYNOPSIS
  1287.        socket = serveraccept(name, peer);
  1288.  
  1289.        long serveraccept(char *, struct sockaddr_in *);
  1290.  
  1291.    DESCRIPTION
  1292.        The serveraccept() library call binds a socket to the named Internet
  1293.        TCP port. Then it listens the socket and accepts the connection to
  1294.        the port. The peer's socket address is returned in sockaddr pointed
  1295.        by sockaddr argument.
  1296.  
  1297.        The port name is resolved by getservbyname() call. A numeric value
  1298.        for port name is also accepted.
  1299.  
  1300.        This module is meant for daemon developing.
  1301.  
  1302.    INPUTS
  1303.        name   - port name or numeric string.
  1304.        peer   - pointer to struct sockaddr_in
  1305.  
  1306.    RESULT
  1307.        socket - positive socket id for success or -1 for failure.
  1308.  
  1309.        peer   - sockaddr_in structure containing peer's internet address.
  1310.                 Note that on error, the structure containing peer address
  1311.                 is not necessarily updated.
  1312.  
  1313.    SEE ALSO
  1314.        bsdsocket/accept, bsdsocket/getservbyname
  1315.  
  1316. net.lib/set_socket_stdio                             net.lib/set_socket_stdio
  1317.  
  1318.    NAME
  1319.        set_socket_stdio - redirect stdio to/from a socket
  1320.  
  1321.    SYNOPSIS
  1322.        int set_socket_stdio(int sock);
  1323.  
  1324.    FUNCTION
  1325.        Redirect stdio (stdin, stdout and stderr) to/from socket 'sock'.
  1326.        This is done by dup2()'ing 'sock' to the level 1 files underneath
  1327.        the stdin, stdout and stderr.
  1328.  
  1329.        The original 'sock' reference is closed on successful return, so
  1330.        the socket descriptor given as argument should not be used after
  1331.        this function returns (successfully).
  1332.  
  1333.    RETURN VALUES
  1334.        0 if successful, -1 on error. Global variable 'errno' contains
  1335.        the specific error code set by the failing function.
  1336.  
  1337.    NOTES
  1338.        This module pulls in the link library stdio modules.
  1339.  
  1340.    SEE ALSO
  1341.        dup2()
  1342. net.lib/sleep                                                   net.lib/sleep
  1343.  
  1344.    NAME
  1345.        sleep - suspend process execution for the specified time
  1346.  
  1347.    SYNOPSIS
  1348.        void sleep(unsigned int seconds);
  1349.  
  1350.    FUNCTION
  1351.        Process execution is suspended for number of seconds specified in 
  1352.        'seconds'. The sleep will be aborted if any of the break signals
  1353.        specified for the process is received (only CTRL-C by default).
  1354.  
  1355.    PORTABILITY
  1356.        UNIX
  1357.  
  1358.    INPUTS
  1359.        'seconds' - number of seconds to sleep.
  1360.  
  1361.    RESULT
  1362.        Does not return a value.
  1363.  
  1364.    NOTES
  1365.        The sleep is implemented as a single select() call with all other
  1366.        than time out argument as NULL.
  1367.  
  1368.    SEE ALSO
  1369.        bsdsocket.library/select()
  1370.  
  1371. net.lib/SPrintf                                               net.lib/SPrintf
  1372.  
  1373.    NAME        
  1374.        SPrintf -- formatted print to a buffer
  1375.  
  1376.    SYNOPSIS
  1377.        len = SPrintf(Buffer, FormatString, Arguments...)
  1378.        len = VSPrintf(Buffer, FormatString, ap)
  1379.  
  1380.        ULONG SPrintf(STRPTR, const char *, ...)
  1381.        ULONG VSPrintf(STRPTR, const char *,  va_list)
  1382.  
  1383.    FUNCTION
  1384.        Prints to a simple buffer or to a CSource buffer. These functions
  1385.        are similar to C-library sprintf() with RawDoFmt() formatting.
  1386.  
  1387.    INPUTS
  1388.        Buffer - Pointer to buffer.
  1389.        FormatString - This is a printf()-style format string as defined
  1390.            in exec.library/RawDoFmt().
  1391.        Arguments - as in printf() .
  1392.  
  1393.        Result - Pointer to CSource structure.
  1394.  
  1395.    RESULT
  1396.        Number of characters printed.
  1397.  
  1398.    EXAMPLE
  1399.        SPrintf(mybuf, "line=%ld, val=%lx\n", 
  1400.                __LINE__, very.interesting->value);
  1401.  
  1402.    BUGS
  1403.        Function SPrintf() assumes that no print is longer than 1024 chars.
  1404.        It does not check for buffer owerflow (there no way to check, the
  1405.        definition of sprintf misses it).
  1406.  
  1407.        SPrintf strings are truncated to maximum of 1024 chars (including
  1408.        final NUL)
  1409.  
  1410.    SEE ALSO
  1411.        exec.library/RawDoFmt()
  1412.  
  1413. net.lib/stat                                                     net.lib/stat
  1414.  
  1415.    NAME
  1416.        stat, lstat, fstat - get file status
  1417.  
  1418.    SYNOPSIS
  1419.        #include <sys/types.h>
  1420.        #include <sys/stat.h>
  1421.  
  1422.        success = stat(path, buf)
  1423.  
  1424.        int stat(const char *, struct stat *);
  1425.  
  1426.        success =  lstat(path, buf);
  1427.  
  1428.        int lstat(const char *, struct stat *);
  1429.  
  1430.        success = fstat(fd, buf);
  1431.  
  1432.        int fstat(int, struct stat *);
  1433.  
  1434.    DESCRIPTION
  1435.        The stat() function obtains information about the file pointed to by
  1436.        path. Read, write or execute permission of the named file is not
  1437.        required, but all directories listed in the path name leading to the
  1438.        file must be seachable.
  1439.  
  1440.        Lstat() is like stat() except in the case where the named file is a
  1441.        symbolic link, in which case lstat() returns information about the
  1442.        link, while stat() returns information about the file the link
  1443.        references.
  1444.  
  1445.        The fstat() obtains the same information about an open file known by
  1446.        the file descriptor fd, such as would be obtained by an open call.
  1447.  
  1448.        Buf is a pointer to a stat() structure as defined by <sys/stat.h>
  1449.        (shown below) and into which information is placed concerning the
  1450.        file.
  1451.  
  1452.           struct  stat
  1453.           {
  1454.             dev_t   st_dev;         /* unique device id */ 
  1455.             ino_t   st_ino;         /* inode of file (key block) */ 
  1456.             mode_t  st_mode;        /* Unix style mode */ 
  1457.             ushort  st_nlink;       /* number of links (unimplemented) */ 
  1458.             uid_t   st_uid;         /* owner's user ID */ 
  1459.             gid_t   st_gid;         /* owner's group ID */ 
  1460.             dev_t   st_rdev;        /* special file ID (unimplemented) */ 
  1461.             off_t   st_size;        /* file size */ 
  1462.             time_t  st_atime;       /* Time of last access */ 
  1463.             time_t  st_mtime;       /* Last modification time */ 
  1464.             time_t  st_ctime;       /* Last file status change time */ 
  1465.             long    st_blksize;     /* Size of disk block */ 
  1466.             long    st_blocks;      /* Size in blocks */ 
  1467.             long    st_dosmode;     /* DOS protection bits */ 
  1468.             short   st_type;        /* DOS file type */ 
  1469.             char   *st_comment;     /* DOS file comment */ 
  1470.           };
  1471.  
  1472.        The time-related fields of struct stat have same contents, time when
  1473.        file data last modified.
  1474.  
  1475.        The status information word st_mode has bits as follows:
  1476.  
  1477.          #define S_ISUID  0004000    /* set user id on execution */ 
  1478.          #define S_ISGID  0002000    /* set group id on execution */ 
  1479.          #define S_ISVTX  0001000    /* save swapped text even after use */ 
  1480.          #define S_IRUSR  0000400    /* read permission for owner */ 
  1481.          #define S_IWUSR  0000200    /* write permission for owner */ 
  1482.          #define S_IXUSR  0000100    /* execute permission for owner */ 
  1483.          #define S_IRGRP  0000040    /* read permission for group */ 
  1484.          #define S_IWGRP  0000020    /* write permission for group */ 
  1485.          #define S_IXGRP  0000010    /* execute permission for group */ 
  1486.          #define S_IROTH  0000004    /* read permission for other */ 
  1487.          #define S_IWOTH  0000002    /* write permission for other */ 
  1488.          #define S_IXOTH  0000001    /* execute permission for other */ 
  1489.          #define S_IFCHR  0020000    /* character special */ 
  1490.          #define S_IFDIR  0040000    /* directory */ 
  1491.          #define S_IFBLK  0060000    /* block special */ 
  1492.          #define S_IFREG  0100000    /* regular */ 
  1493.          #define S_IFLNK  0120000    /* symbolic link */ 
  1494.          #define S_IFSOCK 0140000    /* socket */ 
  1495.          #define S_IFIFO  0010000    /* named pipe (fifo) */ 
  1496.  
  1497.        For a list of access modes, see <sys/stat.h>, access(2) and chmod(2).
  1498.  
  1499.    RETURN VALUES
  1500.        Upon successful completion a value of 0 is returned.  Otherwise, a
  1501.        value of -1 is returned and errno is set to indicate the error.
  1502.  
  1503.    ERRORS
  1504.        The functions stat() and lstat() will fail if:
  1505.  
  1506.        [ENOTDIR]       A component of the path prefix is not a directory.
  1507.  
  1508.        [ENAMETOOLONG]  A component of a pathname exceeded 255 characters,
  1509.                        or an entire path name exceeded 1023 characters.
  1510.  
  1511.        [ENOENT]        The named file does not exist.
  1512.  
  1513.        [ELOOP]         Too many symbolic links were encountered in
  1514.                        translating the pathname.
  1515.  
  1516.        [EACCES]        Search permission is denied for a component of the
  1517.                        path prefix.
  1518.  
  1519.        [EFAULT]        Buf or name points to an invalid address.
  1520.  
  1521.        [EIO]           An I/O error occurred while reading from or writing
  1522.                        to the file system.
  1523.  
  1524.        The function fstat() will fail if:
  1525.  
  1526.        [EBADF]   fd is not a valid open file descriptor.
  1527.  
  1528.        [EFAULT]  Buf points to an invalid address.
  1529.  
  1530.        [EIO]     An I/O error occurred while reading from or writing to the
  1531.                  file system.
  1532.  
  1533.    SEE ALSO
  1534.        chmod(),  chown()
  1535.  
  1536.    BUGS 
  1537.        Applying fstat to a socket returns a zero'd buffer.
  1538.  
  1539. net.lib/strerror                                             net.lib/strerror
  1540.  
  1541.    NAME
  1542.        strerror -- return the text for given error number
  1543.  
  1544.    SYNOPSIS
  1545.        string = strerror(error);
  1546.  
  1547.        char * strerror(int);
  1548.  
  1549.    FUNCTION
  1550.        This function returns pointer to the (English) string describing the
  1551.        error code given as argument. The error strings are defined for the
  1552.        error codes defined in <sys/errno.h>.
  1553.  
  1554.    NOTES
  1555.        The string pointed to by the return value should not be modified by
  1556.        the program, but may be overwritten by a subsequent call to this
  1557.        function.
  1558.  
  1559.    BUGS
  1560.        The strerror() prototype should be 
  1561.        const char *strerror(unsigned int); 
  1562.        However, the SAS C includes define it differently.
  1563.  
  1564.    SEE ALSO
  1565.        <netinclude:sys/errno.h>, perror(), PrintNetFault()
  1566. net.lib/syslog                                                 net.lib/syslog
  1567.  
  1568.    NAME   
  1569.        openlog(), closelog(), setlogmask() -- syslog utility functions
  1570.  
  1571.    SYNOPSIS
  1572.        #include <syslog.h>
  1573.        
  1574.        openlog(ident, logopt, facility);
  1575.  
  1576.        void openlog(const char *, int, int);
  1577.  
  1578.        closelog();
  1579.  
  1580.        void closelog(void);
  1581.  
  1582.        oldmask = setlogmask(maskpri);
  1583.        
  1584.        int setlogmask(int);
  1585.        
  1586.    FUNCTION
  1587.        openlog() can be called to initialize the log file, if special
  1588.        processing is needed.  ident is a string that precedes every
  1589.        message.  logopt is a mask of bits, logically OR'ed together,
  1590.        indicating logging options.  The values for logopt are:
  1591.        
  1592.             LOG_PID             Log the process ID with each message;
  1593.                                 useful for identifying instantiations
  1594.                                 of daemons.
  1595.  
  1596.             LOG_CONS            Force writing messages to the console
  1597.                                 if unable to send it to syslogd.
  1598.                                 This option is safe to use in daemon
  1599.                                 processes that have no controlling
  1600.                                 terminal because syslog() forks
  1601.                                 before opening the console.
  1602.  
  1603.             LOG_NDELAY          Open the connection to syslogd
  1604.                                 immediately.  Normally, the open is
  1605.                                 delayed until the first message is
  1606.                                 logged.  This is useful for programs
  1607.                                 that need to manage the order in
  1608.                                 which file descriptors are allocated.
  1609.  
  1610.             LOG_NOWAIT          Do not wait for children forked to
  1611.                                 log messages on the console. Obsolete
  1612.                                 in AmiTCP/IP, since AmiTCP/IP does
  1613.                                 not fork.
  1614.  
  1615.        facility encodes a default facility to be assigned to all
  1616.        messages written subsequently by syslog() with no explicit
  1617.        facility encoded. The facility codes are:
  1618.  
  1619.             LOG_KERN            Messages generated by the kernel.
  1620.                                 These cannot be generated by any user
  1621.                                 processes.
  1622.  
  1623.             LOG_USER            Messages generated by random user
  1624.                                 processes.  This is the default
  1625.                                 facility identifier if none is
  1626.                                 specified.
  1627.  
  1628.             LOG_MAIL            The mail system.
  1629.  
  1630.             LOG_DAEMON          System daemons, such as inetd, ftpd,
  1631.                                 etc.
  1632.  
  1633.             LOG_AUTH            The authorization system: login, su,
  1634.                                 getty, etc.
  1635.  
  1636.             LOG_LPR             The line printer spooling system: lp,
  1637.                                 lpsched, etc.
  1638.  
  1639.             LOG_LOCAL0          Reserved for local use. Similarly for
  1640.                                 LOG_LOCAL1 through LOG_LOCAL7.
  1641.  
  1642.  
  1643.        closelog() closes the log file.
  1644.  
  1645.        setlogmask() sets the log priority mask to maskpri and returns
  1646.        the previous mask.  Calls to syslog() with a priority not set
  1647.        in maskpri are rejected.  The mask for an individual priority
  1648.        pri is calculated by the macro LOG_MASK(pri); the mask for all
  1649.        priorities up to and including toppri is given by the macro
  1650.        LOG_UPTO(toppri).  By default, all priorities are logged.
  1651.  
  1652.    EXAMPLES
  1653.        who logs a message regarding some sort of unexpected and
  1654.        serious error:
  1655.  
  1656.            syslog(LOG_ALERT, "who: internal error 23");
  1657.  
  1658.        ftpd uses openlog() to arrange to log its process ID, to log
  1659.        to the console if necessary, and to log in the name of the
  1660.        daemon facility:
  1661.  
  1662.            openlog("ftpd", LOG_PID|LOG_CONS, LOG_DAEMON);
  1663.  
  1664.        Arrange to log messages only at levels LOG_ERR and lower:
  1665.  
  1666.            setlogmask(LOG_UPTO(LOG_ERR));
  1667.  
  1668.        Typical usage of syslog() to log a connection:
  1669.  
  1670.            syslog(LOG_INFO, "Connection from host %d", CallingHost);
  1671.  
  1672.        If the facility has not been set with openlog(), it defaults
  1673.        to LOG_USER.
  1674.  
  1675.        Explicitly set the facility for this message:
  1676.  
  1677.            syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
  1678.        
  1679.    NOTES
  1680.        openlog() does not copy and store the ident string internally;
  1681.        it stores only the character pointer.  Therefore it is the
  1682.        responsibility of the programmer to make sure that the ident
  1683.        argument points to the correct string while syslog() is being
  1684.        called. 
  1685.  
  1686.    BUGS
  1687.        Most of the logopt and facility codes are currently being
  1688.        ignored by AmiTCP/IP, but they should be used for future
  1689.        compatibility.
  1690.  
  1691.        The autoinit module of the net.lib tells the program name 
  1692.        to the AmiTCP/IP at program startup, so use of the openlog()
  1693.        for that purpose only is not necessary.
  1694.  
  1695.    AUTHOR
  1696.        syslog() was developed by the University of California,
  1697.        Berkeley.
  1698.  
  1699.    SEE ALSO
  1700.        bsdsocket.library/syslog(), bsdsocket.library/SocketBaseTagList()
  1701. net.lib/usleep                                                 net.lib/usleep
  1702.  
  1703.    NAME
  1704.        usleep - suspend process execution for the specified time
  1705.  
  1706.    SYNOPSIS
  1707.        void usleep(unsigned int microseconds);
  1708.  
  1709.    FUNCTION
  1710.        Process execution is suspended for number of microseconds
  1711.        specified in 'microseconds'. The sleep will be aborted if any
  1712.        of the break signals specified for the process is received
  1713.        (only CTRL-C by default).
  1714.  
  1715.    PORTABILITY
  1716.        UNIX
  1717.  
  1718.    INPUTS
  1719.        'microseconds' - number of microseconds to sleep.
  1720.  
  1721.    RESULT
  1722.        Does not return a value.
  1723.  
  1724.    NOTES
  1725.        The sleep is implemented as a single select() call with all other
  1726.        than time out argument as NULL.
  1727.  
  1728.    SEE ALSO
  1729.        bsdsocket.library/select()
  1730.  
  1731. net.lib/utime                                                   net.lib/utime
  1732.  
  1733.    NAME
  1734.        utime - set file access and modification times
  1735.  
  1736.    SYNOPSIS
  1737.        #include <utime.h>
  1738.  
  1739.        int error = utime(const char *name, const struct utimbuf *times)
  1740.  
  1741.    FUNCTION
  1742.        The access and modification times for the file 'name' are modified
  1743.        according to the 'times'. If 'times' is NULL, the times are set to
  1744.        systems current time.
  1745.  
  1746.    PORTABILITY
  1747.        UNIX
  1748.  
  1749.    INPUTS
  1750.        'name'  - the name of the file to be affected.
  1751.  
  1752.        'times' - pointer to a structure containing the time values,
  1753.                  defined in <utime.h> as:
  1754.  
  1755.                      struct utimbuf {
  1756.                          time_t actime;        /* Access time */
  1757.                          time_t modtime;        /* Modification time */
  1758.                      };
  1759.  
  1760.                  Both times are in units of seconds since Jan. 1, 1970,
  1761.                  Greenwich Mean Time.
  1762.  
  1763.                  If the 'times' is given as the NULL pointer, the current
  1764.                  time is used.
  1765.  
  1766.    RESULT
  1767.        Returns 0 when successful and -1 with specific error code in errno in
  1768.        case of an error.
  1769.  
  1770.    NOTES
  1771.        Since AmigaDOS files have only one time stamp, both access and
  1772.        modification times cannot be supported. Since the AmigaDOS file date
  1773.        is the modification time, only the 'modtime' field of the 'times' is
  1774.        used.
  1775.  
  1776.        The conversion from 1.1.1970 based GMT to 1.1.1978 based local time is
  1777.        done with external long __local_to_GMT, which is defined and
  1778.        initialized by the timerinit.c module included in the net.lib.
  1779.  
  1780.    SEE ALSO
  1781.        dos.library/DateStamp(), dos.library/SetFileDate(), net.lib/timerinit
  1782.  
  1783. netd.lib/dosio_init                                       netd.lib/dosio_init
  1784.  
  1785.    NAME
  1786.        dosio_init - (std) io macros to dos.library V37 or newer
  1787.  
  1788.    SYNOPSIS
  1789.        long _STI_500_dosio_init(void)
  1790.  
  1791.    FUNCTION
  1792.        This function initializes the file table used by the stdio
  1793.        look-a-like macros defined in <netinclude:stdio.h>.
  1794.  
  1795.        These macros are taken in to use by defining the symbol
  1796.        `USE_DOSIO' before including any include files.  When this is
  1797.        done, the normal stdio prototypes are replaced with macros,
  1798.        which call the corresponding dos.library functions.  The
  1799.        netd.lib provides the initialization function mentioned above
  1800.        and the functions VSPrintf(), SPrintf(), VCSPrintf() and
  1801.        CSPrintf(), which are not found from the dos.library.
  1802.  
  1803.        The stdio macros provided are suitable for stdin, stdout and
  1804.        stderr usage. No file opening function (fopen()) is provided,
  1805.        so the use is quite limited.
  1806.  
  1807.        The netd.lib version of the net.lib is compiled with this
  1808.        USE_DOSIO, so you will want to use that instead of the
  1809.        net.lib to make your executable smaller if your own program
  1810.        does not use stdio of the C runtime library.
  1811.  
  1812.    NOTES
  1813.        The stdio macros rely on dos.library 37 or newer being present.
  1814.  
  1815.        The autoinitialization and autotermination functions are features
  1816.        specific to the SAS C6.  However, these functions can be used with
  1817.        other (ANSI) C compilers, too. Example follows:
  1818.  
  1819.        /* at start of main() */
  1820.  
  1821.        if (_STI_500_dosio_init() != 0)
  1822.           exit(20);
  1823.  
  1824.    BUGS
  1825.        The same autoinitialization won't work for both SAS C 6.3 and SAS C
  1826.        6.50 or latter.  Only way to terminate an initialization function is
  1827.        by exit() call with SAS C 6.3 binary.  If an autoinitialization
  1828.        function is terminated by exit() call with SAS C 6.50 binary, the
  1829.        autotermination functions won't be called.  Due this braindamage
  1830.        the libraries must be separately compiled for each compiler version.
  1831.  
  1832.    SEE ALSO
  1833.  
  1834.  
  1835.